<template>
<div class="home"> 
      <!-- 折线图 -->
    <div class="chart" id="line"></div>
      <!-- 柱形图图 -->
    <div class="chart" id="bar"></div>
      <!-- 饼状图 -->
    <div class="chart" id="pie"></div>
      <!-- 散点图 -->
    <div class="chart" id="scatter"></div>
</div>
</template>
<script>
import * as echarts from "echarts"
import { mapGetters, mapActions } from "vuex"
 export default {
props: [],
data() {
return {};
},
computed: {
 ...mapGetters({
     arr:"cate/arr"
 }),
},
mounted() {
     //请求分类的数据
     this.reqArr().then(()=>{
        console.log(this.arr);
         this.doline()
         this.doBar()
         this.doPie()
     })
    
},
methods: {
...mapActions({
    reqArr:"cate/reqArr"
}),
  //画折线图
 doline(){
// 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('line'));
//配置项
let option = {
  xAxis: {
    type: 'category',
    data: this.arr.map(item=>item.catename)
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: this.arr.map(item=>item.children?item.children.length:0 ),
      type: 'line'
    }
  ]
};
// 绘制图表
myChart.setOption(option);
    },
//柱形图
doBar(){
 // 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('bar'));
//配置项
let option = {
  title: {
    text: 'ECharts 入门示例'
  },
  tooltip: {},
  xAxis: {
    data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
  },
  yAxis: {},
  series: [
    {
      name: '销量',
      type: 'bar',
      data: [5, 20, 36, 10, 10, 20]
    }
  ]
};
// 绘制图表
myChart.setOption(option);   
},
//饼状图
doPie(){
 // 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('pie'));
//配置项
let option = {
  title: {
    text: 'Referer of a Website',
    subtext: 'Fake Data',
    left: 'center'
  },
  tooltip: {
    trigger: 'item'
  },
  legend: {
    orient: 'vertical',
    left: 'left'
  },
  series: [
    {
      name: 'Access From',
      type: 'pie',
      radius: '50%',
      data: [
        { value: 1048, name: 'Search Engine' },
        { value: 735, name: 'Direct' },
        { value: 580, name: 'Email' },
        { value: 484, name: 'Union Ads' },
        { value: 300, name: 'Video Ads' }
      ],
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }
  ]
};
// 绘制图表
myChart.setOption(option);   
},


  },
 };
</script>

<style scoped lang="less">
@import "../../less/index.less";
.home{
    overflow: hidden;
    .chart{
        width: 48%;
        float: left;
        margin: 10px;
        background: #ccc;
        height: 300px;
    }
}
</style>